package mytaxy.tpagp.Reminder;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

public class MyReceiver extends android.content.BroadcastReceiver {  
	private static final int ALARM_REQUEST_CODE = 1;
	
	public void onReceive(android.content.Context context, android.content.Intent intent) {  
	    
		Bundle bun = intent.getExtras();
		String atributos = bun.getString("msg");
	
		/* 0.month 1.day 2.year 3.hour 4.min 5.method 6.freq*/
		String [ ] atr = atributos.split("\\ ");
		Toast.makeText(context, "Ha solicitat un TAXI: el "+atr[1]+"-"+atr[0]+"-"+atr[2]+ " a les " +atr[3]+":"+atr[4] , Toast.LENGTH_LONG).show();
		
		//Cridem l'intent
      	AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      	Intent intent1  = new Intent("mytaxy.tpagp.reminder.android.alarmmanager");
      	intent1.putExtra("msg", atributos);
      	PendingIntent pIntent = PendingIntent.getBroadcast(context, ALARM_REQUEST_CODE, intent1,  PendingIntent.FLAG_CANCEL_CURRENT);
        manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pIntent);  
		
		/*Phone Call
		String posted_by = "111-333-222-4";

		String uri = "tel:" + posted_by.trim() ;
		Intent intent = new Intent(Intent.ACTION_CALL);
		intent.setData(Uri.parse(uri));
		startActivity(intent);
		*/
    }
}